#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char link[1024];
char end[1024];

int main()
{
	int del_cnt;

	scanf("%s", link);
	scanf("%d", &del_cnt);
	{
		char *p, *d, *s, str[del_cnt][32];
		int i, f = 0, first = 1;

		for (i = 0; i < del_cnt; i++)
			scanf("%s", str[i]);

		p = link;
		d = end;
		
		strcpy(end, link);

		p = strstr(link, "?");
		d = strstr(end, "?");
		s=p;

		while(1) {
			int l = 0, r = 0;

			while(*p != '=') {
				p++;
				l++;
			}

			for (i = 0; i < del_cnt; i++) {
				if (strncmp(s + 1, str[i], l - 1) == 0) {
					r = 1;
					break;
				} 
			}
			while (*p != '&' && *p != '\0') {
				p++;
				l++;
				if (*p == '\0') {
					f = 1;
					break;
				}
			}
			if (r == 0) {
				strncpy(d, s, l);
				if (first) {
					*d = '?';
					first = 0;
				}
				d += l;
			} 	
			s += l;

			if (f) {
				*d = '\0';
				break;
			}
			r = 0;
			l = 0;
		}
	}
	
	printf("%s\n", end);

	return 0;
}
